package com.learn.multDataSource.service.mysql.impl;

import com.learn.multDataSource.mapper.mysql.TKnowMapper;
import com.learn.multDataSource.model.mysql.TKnow;
import com.learn.multDataSource.model.mysql.TKnowExample;
import com.learn.multDataSource.service.mysql.KnowService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("knowService")
public class KnowServiceImpl implements KnowService {

    @Resource
    private TKnowMapper tKnowMapper;

    @Override
    @Transactional(readOnly = true)
    public TKnow findById(Long knowId) {
        TKnow know = tKnowMapper.selectByPrimaryKey(knowId);
        System.out.println(know);
        return know;
    }

    @Override
    @Transactional(readOnly = true)
    public List<TKnow> findAll() {
        TKnowExample example = new TKnowExample();
        TKnowExample.Criteria criteria = example.createCriteria();
        return tKnowMapper.selectByExample(example);
    }

    @Override
    @Transactional()
    public void save(TKnow know) {
        tKnowMapper.insertSelective(know);
    }
}
